<?php 

// send.php
  require 'inc.php';
if(!class_exists('member'))
{
	require $MODULE['member']['url'].'include/member.class.php';
}
if(!$_userid)  showmessage('请登录后再发送短消息', url("?module=member&action=login&forward=".urlencode(URL)));
if(!isset($forward)) $forward = HTTP_REFERER;



	
 switch($action){
 	case 'read':
		
		require 'form.class.php';
		
		if ($dosubmit)
		{
			if(empty($content))
			{
				showmessage('短消息不能为空');
			}
			if(!$message->reply($replyid, $msgtoid, $_userid, $content))
			{
				showmessage($message->msg(), $forward);
			}
			$memberinfo = array('userid'=>$msgtoid, 'message'=>1);
			$member->edit($memberinfo);
			showmessage('短消息回复成功', $forward);
		}
		else
		{
			$message_info = $out ? $message->read_send($_userid, $msgid) : $message->read($_userid, $msgid);
			
			if(!$message_info)
			{
				showmessage($message->msg(), $forward);
			}
			$box = $out ? $LANG['outbox'] : $LANG['inbox'];
			@extract($message_info);
			$msgtoid = $out ? $send_to_id : $send_from_id;
			unset($message_info);
			$reply_message = $message->list_reply($msgid);
			$head['title'] = $LANG['msg_center'];
			include template('read.html',$module);
		}
		
	break;
	
	case 'send':
		
		if($dosubmit)
		{
			checkcode($checkcodestr, 1); 
			$arr_user = explode(',', $msgto);
			foreach($arr_user as $nickname)
			{
				$member = new member;
				$msgtoid = $member->get_userid($nickname,'nickname');
				if(!$message->send_new($msgtoid, $_userid, $subject, $content, $savetooutbox))
				{
					showmessage($message->msg(), $forward);
				}
				$memberinfo = array('userid'=>$msgtoid, 'message'=>1);
				$member->edit($memberinfo);
			}	
			unset($arr_msgtoname, $message_limit, $num_message, $member);
			showmessage($LANG['message_send_successful'], $forward);
		}
		else
		{
			require 'form.class.php';
			$head['title'] = $LANG['send_msg'];
			if(isset($userid))
			{
				$member = new member;
				$result = $member->get($userid);
				$username = $result['username'];
			}
			include template('send.html',$module);
		}
		
	break;
	
	case 'checkuser':
		$arr_user = explode(',', $value);
		foreach($arr_user as $nickname)
		{
			$userid = $member->get_userid($nickname,'nickname');
			if(!$userid) exit($nickname.'会员不存在');
			if($userid==$_userid) exit('不能给本人发短消息！');
			$result = $member->get($userid, 'disabled');
			//if($result['disabled']) exit($nickname.'已经被禁用');
		}
		exit('success');
	break;
	
	// AJAX收到短消息提示
	case 'get_message':
		echo $_message ? 1 : 0;
		break;
	break;
	
	default:
		header('location: '.url("?module=message&file=inbox")); 
	break;
 }

?>
